﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Core;
using System.IO;
namespace BallData
{
    class ZipHelper
    {
        public static byte[] Zip(byte[] data)
        {
            MemoryStream mstream = new MemoryStream();
            BZip2OutputStream zipOutStream = new BZip2OutputStream(mstream);
            zipOutStream.Write(data, 0, data.Length);
            zipOutStream.Close();
            byte[] result = mstream.ToArray();
            mstream.Close();
            return result;
        }
        public static byte[] Unzip(byte[] data)
        {
            MemoryStream mstream = new MemoryStream(data);
            BZip2InputStream zipInputStream = new BZip2InputStream(mstream);
            StreamReader readstream = new StreamReader(zipInputStream,Encoding.Default);
            String unzipdata = readstream.ReadToEnd();

            zipInputStream.Close();
            mstream.Close();
            return Encoding.Default.GetBytes(unzipdata);
        }
        
        
    }
}
